home *** CD-ROM | disk | FTP | other *** search
/ Screensavers 98 / Screensavers 98.iso / scr / pyro / firemain.cpp < prev    next >
C/C++ Source or Header  |  2000-03-28  |  44KB  |  1,133 lines

  1. // *** Fire work Demostration Screen Saver Program ***
  2. // ***** Written by Steven De Toni Febyary 1996 ******
  3. // ***************************************************
  4.  
  5. #include <windows.h>
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. // ***** Include object information *****
  11. #include "config.h"     // Configuration file define constants
  12. #include "ctl3d.h"      // Fancey look to dialog boxes in Win3.1.
  13. #include "fclasses.h"
  14. #include "fix.h"
  15.  
  16.  
  17. // Program varibales !
  18. const  char*      pSzProgName = "Fire Work Screen Saver"; // Program name.
  19. const  int        StrSize     = 256;                  // String size for string processing.
  20. static HINSTANCE  HInst;                              // Handle to main window of application.
  21.  
  22. // *** Prototypes ***
  23. long FAR PASCAL _export    WndProc              (HWND hWnd, WORD message, WORD wParam, LONG lParam);
  24. BOOL FAR PASCAL _export    ConfigDialog         (HWND hDlg, WORD message, WORD wParam, LONG lParam);
  25. BOOL FAR PASCAL _export    SetPasswordDialog    (HWND hDlg, WORD message, WORD wParam, LONG lParam);
  26. BOOL FAR PASCAL _export    GetUserPDialog       (HWND hDlg, WORD message, WORD wParam, LONG lParam);
  27. int UpdateField (HWND hDlg, int cntlID, int direction, int heightLimit, int lowLimit);
  28.  
  29. // Spinner and field entry limits in configuration dialog.
  30. const int ObjRocketMax   = 9000,  ObjRocketMin   = 0;
  31. const int ObjFlowerMax   = 9000,  ObjFlowerMin   = 0;
  32. const int ObjFlareMax    = 9000,  ObjFlareMin    = 1;
  33. const int ObjTrailerMax  = 50,    ObjTrailerMin  = 1;
  34. const int ObjLifeMax     = 2000,  ObjLifeMin     = 10;
  35. const int ObjPicSizeMax  = 4,     ObjPicSizeMin  = 1;
  36.  
  37. const int PicFreqMax     = 10,    PicFreqMin     = 1;
  38. const int PicAngleMax    = 20,    PicAngleMin    = -20;
  39. const int FrameRate      = 0;
  40.  
  41. // Default INI settings.
  42. const char* Section        = "Configuration";
  43. const char* DefIniSettings = "1 50 10 50 1 50 10 100 1 ~ 0";
  44.  
  45. // Timer ID constant.
  46. const int TIMERMAIN   = 10;  // Timer ID within function.
  47. const int TIMERABOUT  = 11;
  48. const int TIMERCONFIG = 12;
  49.  
  50. // Time limit variables for entering password.
  51. const  long PASSWORDCYCLIMIT = 3000; // Timit limit to enter password before dialod is removed.
  52. static long CurrentCycle     = 0;
  53. static HWND HPassDialog      = NULL; // Varible used to commincate with
  54.                                      // Password dialog box, and close it
  55.                                      // after a certain time. If variable is
  56.                                      // not null, then password dialog box is
  57.                                      // open.
  58.  
  59.  
  60. // Current system screen size.
  61. int MAXX, MAXY;
  62.  
  63. // Configuration variables for screen saver.
  64. // These variables are stored in the INI file (win.ini)
  65. static int    RocketNum;
  66. static int    RocketFlareNum;
  67. static int    RocketTrailLen;
  68. static int    RocketLifeCount;
  69.  
  70. static int    FlowerNum;
  71. static int    FlowerFlareNum;
  72. static int    FlowerTrailLen;
  73. static int    FlowerLifeCount;    
  74.  
  75. extern int    PixelSize;            // Pixel size of objects, definied in class definition file.
  76.  
  77. static char   Password   [StrSize/5];
  78. static int    UsePassword;
  79.  
  80.  
  81. // ***************************************************************************************
  82. // Program Entry, and exit.
  83. // ***************************************************************************************
  84. int PASCAL WinMain  (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
  85. {
  86.     HWND            hwnd;
  87.     MSG             msg;
  88.     WNDCLASS        wndclass;
  89.     char            paramBuff[StrSize];
  90.  
  91.     HInst = hInstance;                                  // Assign program instance
  92.     randomize();
  93.  
  94.     if (!hPrevInstance)
  95.     {
  96.         wndclass.style                = CS_BYTEALIGNWINDOW | CS_HREDRAW | CS_VREDRAW;
  97.         wndclass.lpfnWndProc          = (WNDPROC) WndProc;
  98.         wndclass.cbClsExtra           = 0;
  99.         wndclass.hInstance            = HInst;
  100.         wndclass.hIcon                = NULL;
  101.         wndclass.hCursor              = LoadCursor (HInst, MAKEINTRESOURCE(BLANKCURSOR));
  102.         wndclass.hbrBackground        = GetStockObject (BLACK_BRUSH);
  103.         wndclass.lpszMenuName         = NULL;
  104.         wndclass.lpszClassName        = pSzProgName;
  105.         
  106.         RegisterClass (&wndclass);      
  107.     }
  108.     else
  109.         return 0;   // Don't more than one instance of the screen saver
  110.  
  111.     MAXX  = GetSystemMetrics(SM_CXSCREEN);
  112.     MAXY  = GetSystemMetrics(SM_CYSCREEN);
  113.  
  114.     // Check parameter string for configuration command /c
  115.     lstrcpy (paramBuff, lpszCmdParam);
  116.     strupr (paramBuff);
  117.     if (strstr (paramBuff, "/C") != NULL)
  118.     {       
  119.         // Setup the control 3D sub-classing DLL.
  120.         Ctl3dRegister(HInst);
  121.         Ctl3dAutoSubclass(HInst);
  122.  
  123.         // Test Configuration Dialog.
  124.         static FARPROC fpfnConfigDialog;
  125.         fpfnConfigDialog = MakeProcInstance ((FARPROC)ConfigDialog, HInst);
  126.         DialogBox (HInst, MAKEINTRESOURCE(IDD_CONFIGDIALOG), NULL, (DLGPROC) fpfnConfigDialog);
  127.         FreeProcInstance (fpfnConfigDialog);
  128.  
  129.         // Free up usage count of 3D DLL.
  130.         Ctl3dUnregister(HInst);
  131.         return 0;
  132.     }
  133.  
  134.     // Create Screen Saver window.
  135.     hwnd  = CreateWindowEx (WS_EX_TOPMOST,
  136.                          pSzProgName,                   // Window class name
  137.                          "",                            // Window caption
  138.                          WS_POPUP,                      // Window style
  139.                          0,                             // inital X position
  140.                          0,                             // inital y position 
  141.                          MAXX,                          // inital X size
  142.                          MAXY,                          // intial y size
  143.                          NULL,                          // parent window handle
  144.                          NULL,                          // window menu handle
  145.                          HInst,                         // program instance handle
  146.                          NULL);                         // creation parameters
  147.  
  148.  
  149.     // Setup Screen saver timer.
  150.     SetTimer(hwnd, TIMERMAIN, FrameRate, (TIMERPROC) WndProc);
  151.  
  152.     // Go into screen saver mode. 
  153.     ShowWindow (hwnd, nCmdShow);
  154.     UpdateWindow (hwnd);
  155.  
  156.     // Process screen saver messages...
  157.     while (GetMessage (&msg, NULL, 0, 0))
  158.     {
  159.         
  160.         TranslateMessage (&msg);
  161.         DispatchMessage  (&msg);
  162.     }
  163.  
  164.     return msg.wParam;
  165. }
  166.  
  167. // Pic one of the primary colours
  168. COLORREF PicColour (void)
  169. {
  170.     // select primary colour
  171.     switch (random(7))
  172.     {
  173.         case 0:
  174.              return RGB (255, 0, 0);
  175.  
  176.         case 1:
  177.              return RGB (0, 255, 0);
  178.  
  179.         case 2:
  180.              return RGB (0, 0, 255);
  181.  
  182.         case 3:
  183.              return RGB (255, 255, 0);
  184.  
  185.         case 4:
  186.              return RGB (0, 255, 255);
  187.  
  188.         case 5:
  189.              return RGB (255, 0, 255);
  190.  
  191.         case 6:
  192.         default:
  193.              return RGB (255, 255, 255);
  194.     }
  195. }
  196.  
  197.  
  198. // ***************************************************************************
  199. // *** Get User Password Dialog Box. Open up the dialog box to recieve the
  200. // *** user's password.
  201. // ***************************************************************************
  202. BOOL FAR PASCAL _export GetUserPDialog (HWND hDlg, WORD message, WORD wParam, LONG lParam)
  203. {
  204.     switch (message)
  205.     {
  206.         case WM_INITDIALOG:
  207.              HPassDialog  = hDlg;
  208.              CurrentCycle = 0;
  209.              SetActiveWindow (GetDlgItem(hDlg, IDC_GETPASSWORD));
  210.              return TRUE;
  211.  
  212.         case WM_CHAR:
  213.              MessageBeep (-1);
  214.              break;
  215.  
  216.         case WM_KEYDOWN:
  217.         case WM_SYSKEYDOWN:
  218.              return TRUE;
  219.  
  220.         case WM_COMMAND:    // A user has selected a control command
  221.             switch (LOWORD (wParam))
  222.             {
  223.                 case IDC_CANCEL:
  224.                     EndDialog (hDlg, FALSE);
  225.                     HPassDialog = NULL;
  226.                     return TRU